package com.newtouch.bxzs.policy.service.impl;


import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.newtouch.bxzs.common.base.BaseErrorEnum;
import com.newtouch.bxzs.common.base.BaseException;
import com.newtouch.bxzs.common.base.em.CompanyParameterTypeEnum;
import com.newtouch.bxzs.common.base.em.DistributionTypeEnum;
import com.newtouch.bxzs.common.base.em.PolicyNatureType;
import com.newtouch.bxzs.common.base.em.SystemParamsEnum;
import com.newtouch.bxzs.common.base.util.CooperationCompanyUtils;
import com.newtouch.bxzs.common.base.util.RedisUtils;
import com.newtouch.bxzs.common.base.util.SendHttpRequestUtils;
import com.newtouch.bxzs.common.base.util.UserDetailUtil;
import com.newtouch.bxzs.policy.mapper.PolicyMapper;
import com.newtouch.bxzs.policy.model.bo.*;
import com.newtouch.bxzs.policy.model.vo.*;
import com.newtouch.bxzs.policy.service.PolicyService;
import com.newtouch.bxzs.policy.util.QueryCriteriaUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 保单管理实现类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/7 13:33</td>
 * <td>linhongxi</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author linhongxi
 * @version 1.0.0
 * @since 1.0.0
 */
@Service
public class PolicyServiceImpl implements PolicyService {

    @Resource
    private PolicyMapper policyMapper;

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private CooperationCompanyUtils cooperationCompanyUtils;

    /**
     * 根据查询条件查询个人保单列表信息
     * com.newtouch.bxzs.policy.service.PolicyService#getIndividualPolicyList
     * @param policyVO 个人保单列表信息查询条件
     * @return 个人保单列表信息
     */
    @Override
    public IPage<PolicyListBO> getIndividualPolicyList(PolicyVO policyVO) {
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(policyVO.getPolicyApplicationDate(),policyVO.getPolicyExpirationDate());
        //查询条件--保单号验证
        QueryCriteriaUtils.queryValidationByNumber(policyVO.getPolicyNumber());
        //查询条件--姓名验证
        QueryCriteriaUtils.queryValidationByName(policyVO.getPolicyHolderName(),policyVO.getInsurederName());
        //查询条件--投保人证件验证
        QueryCriteriaUtils.queryValidationByCertificate(policyVO.getPolicyHolderCertificateType(),policyVO.getPolicyHolderCertificateNumber());
        //查询条件--被保人证件验证
        QueryCriteriaUtils.queryValidationByCertificate(policyVO.getInsurederCertificateType(),policyVO.getInsurederCertificateNumber());
        Page<PolicyListBO> policyPage= new Page<>(policyVO.getCurrentPage(),
                policyVO.getPageSize());
        policyVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        return policyMapper.policyListBO(policyVO,policyPage, PolicyNatureType.INDIVIDUAL_POLICY_NATURE.getCode());
    }

    /**
     * 根据保单号查询个人保单详情信息
     * com.newtouch.bxzs.policy.service.PolicyService#getIndividualPolicyInfo
     * @param policyInfoVO 个人保单详情信息查询条件
     * @return 个人保单详情信息
     */
    @Override
    public PolicyBO getIndividualPolicyInfo(PolicyInfoVO policyInfoVO) {
        if(StringUtils.isEmpty(policyInfoVO.getPolicyNumber())){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL.getResultCode(),BaseErrorEnum.REQUEST_DATA_NULL.getResultMsg());
        }
        policyInfoVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        PolicyBO policyBO = new PolicyBO();
        SendHttpRequestUtils<PolicyInfoVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(policyInfoVO, cooperationCompanyUtils.getCompanyUrl(policyInfoVO.getInsuranceCompanyName(),
                    CompanyParameterTypeEnum.QUERY_POLICY_INFO.getCode()));
            Object data = response.get("data");
            if(response != null && !StringUtils.isEmpty(data)){
                policyBO = JSONObject.toJavaObject(JSONObject.parseObject(JSONUtil.toJsonStr(data)),PolicyBO.class);
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(SystemParamsEnum.QUERY_POLICY_INFO.getCode());
            policyBO = JSON.toJavaObject(sendHttpRequest.sendHttpRequestToJson(policyInfoVO, url),PolicyBO.class);
        }
        if(policyBO != null){
            if(!StringUtils.isEmpty(policyBO.getPolicyHolderCertificateNumber()) && !StringUtils.isEmpty(policyBO.getInsurederCertificateNumber())){
                if(policyBO.getPolicyHolderCertificateNumber().equals(policyBO.getInsurederCertificateNumber())){
                    policyBO.setInsurederFlag(true);
                }
            }
            if(!StringUtils.isEmpty(policyBO.getPolicyHolderCertificateNumber()) && !StringUtils.isEmpty(policyBO.getBeneficiaryCertificateNumber())){
                if(policyBO.getPolicyHolderCertificateNumber().equals(policyBO.getBeneficiaryCertificateNumber())){
                    policyBO.setBeneficiaryFlag(true);
                }
            }
        }
        return policyBO;
    }

    /**
     * 根据保单号获取保全列表
     *
     * @param policyInfoPageVO 个人保单详情--保全信息查询条件
     *
     * @return 个人保单详情--保全信息
     */
    @Override
    public List<PreservationBO> getPolicyPreservation(PolicyInfoPageVO policyInfoPageVO){
        if(StringUtils.isEmpty(policyInfoPageVO.getPolicyNumber())){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL.getResultCode(),BaseErrorEnum.REQUEST_DATA_NULL.getResultMsg());
        }
        policyInfoPageVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取个单详情中的保全信息
        SendHttpRequestUtils<PolicyInfoPageVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(policyInfoPageVO, cooperationCompanyUtils.getCompanyUrl(policyInfoPageVO.getInsuranceCompanyName(),
                    CompanyParameterTypeEnum.QUERY_POLICY_INFO_PRESERVATION.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,PreservationBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(SystemParamsEnum.QUERY_POLICY_INFO_PRESERVATION.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(policyInfoPageVO,url).toJSONString(),PreservationBO.class);
        }
        return null;
    }

    /**
     * 根据保单号获取理赔列表
     *
     * @param policyInfoPageVO 个人保单详情--理赔信息查询条件
     *
     * @return 个人保单详情--理赔信息
     */
    @Override
    public List<ClaimsBO> getPolicyClaims(PolicyInfoPageVO policyInfoPageVO){
        if(StringUtils.isEmpty(policyInfoPageVO.getPolicyNumber())){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL.getResultCode(),BaseErrorEnum.REQUEST_DATA_NULL.getResultMsg());
        }
        policyInfoPageVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取个单详情中的理赔信息
        SendHttpRequestUtils<PolicyInfoPageVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(policyInfoPageVO, cooperationCompanyUtils.getCompanyUrl(policyInfoPageVO.getInsuranceCompanyName(),
                    CompanyParameterTypeEnum.QUERY_POLICY_INFO_CLAIMS.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,ClaimsBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(SystemParamsEnum.QUERY_POLICY_INFO_CLAIMS.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(policyInfoPageVO, url).toJSONString(),ClaimsBO.class);
        }
        return null;
    }
    /**
     * 根据查询条件获取新契约进度列表
     *
     * @param policyNewContractVO 个人保单新契约进度列表查询条件
     *
     * @return 个人保单新契约进度列表
     */
    @Override
    public List<PolicyNewContractListBO> getPolicyNewContractList(PolicyNewContractVO policyNewContractVO){
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(policyNewContractVO.getPolicyApplicationDate(),policyNewContractVO.getPolicyExpirationDate());
        //查询条件--投保单号验证
        QueryCriteriaUtils.queryValidationByNumber(policyNewContractVO.getPolicyApplicationNumber());
        //查询条件--姓名验证
        QueryCriteriaUtils.queryValidationByName(policyNewContractVO.getPolicyHolderName(),policyNewContractVO.getInsurederName());
        //查询条件--投保人证件验证
        QueryCriteriaUtils.queryValidationByCertificate(policyNewContractVO.getPolicyHolderCertificateType(),policyNewContractVO.getPolicyHolderCertificateNumber());
        //查询条件--被保人证件验证
        QueryCriteriaUtils.queryValidationByCertificate(policyNewContractVO.getInsurederCertificateType(),policyNewContractVO.getInsurederCertificateNumber());
        policyNewContractVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取新契约保单信息
        SendHttpRequestUtils<PolicyNewContractVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(policyNewContractVO, cooperationCompanyUtils.getCompanyUrl(policyNewContractVO.getInsuranceCompanyName(),
                    CompanyParameterTypeEnum.QUERY_POLICY_NEW_CONTRACT.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,PolicyNewContractListBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(SystemParamsEnum.QUERY_POLICY_NEW_CONTRACT.getCode());
            return JSONArray.parseArray(sendHttpRequest.sendHttpRequestToArray(policyNewContractVO, url).toJSONString(),PolicyNewContractListBO.class);
        }
        return null;
    }

    /**
     * 根据保单号获取新契约进度详情
     *
     * @param policyNewContractInfoVO 个人保单新契约进度详情查询条件
     *
     * @return 个人保单新契约进度详情
     */
    @Override
    public PolicyNewContractInfoBO getPolicyNewContractInfo(PolicyNewContractInfoVO policyNewContractInfoVO){
        if(StringUtils.isEmpty(policyNewContractInfoVO.getPolicyApplicationNumber())){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL.getResultCode(),BaseErrorEnum.REQUEST_DATA_NULL.getResultMsg());
        }
        policyNewContractInfoVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取个单新契约进度详情信息
        PolicyNewContractInfoBO policyNewContractInfoBO = new PolicyNewContractInfoBO();
        SendHttpRequestUtils<PolicyNewContractInfoVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(policyNewContractInfoVO, cooperationCompanyUtils.getCompanyUrl(policyNewContractInfoVO.getInsuranceCompanyName(),
                    CompanyParameterTypeEnum.QUERY_POLICY_NEW_CONTRACT_INFO.getCode()));
            Object data = response.get("data");
            if(response != null && !StringUtils.isEmpty(data)){
                policyNewContractInfoBO = JSONObject.toJavaObject(JSONObject.parseObject(JSONUtil.toJsonStr(data)),PolicyNewContractInfoBO.class);
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(SystemParamsEnum.QUERY_POLICY_NEW_CONTRACT_INFO.getCode());
            policyNewContractInfoBO = JSON.toJavaObject(sendHttpRequest.sendHttpRequestToJson(policyNewContractInfoVO, url),PolicyNewContractInfoBO.class);
        }
        if(policyNewContractInfoBO != null){
            if(!StringUtils.isEmpty(policyNewContractInfoBO.getPolicyHolderCertificateNumber()) && !StringUtils.isEmpty(policyNewContractInfoBO.getInsurederCertificateNumber())){
                if(policyNewContractInfoBO.getPolicyHolderCertificateNumber().equals(policyNewContractInfoBO.getInsurederCertificateNumber())){
                    policyNewContractInfoBO.setInsurederFlag(true);
                }
            }
            if(!StringUtils.isEmpty(policyNewContractInfoBO.getPolicyHolderCertificateNumber()) && StringUtils.isEmpty(policyNewContractInfoBO.getBeneficiaryCertificateNumber())){
                if(policyNewContractInfoBO.getPolicyHolderCertificateNumber().equals(policyNewContractInfoBO.getBeneficiaryCertificateNumber())){
                    policyNewContractInfoBO.setBeneficiaryFlag(true);
                }
            }
        }
        return policyNewContractInfoBO;
    }

    /**
     * 根据查询条件获取保全进度列表
     *
     * @param preservationVO 个人保单保全进度列表查询条件
     *
     * @return 个人保单保全进度列表
     */
    @Override
    public List<PreservationProgressListBO> getPreservationProgressList(PreservationVO preservationVO){
        //查询条件--保单号验证
        QueryCriteriaUtils.queryValidationByNumber(preservationVO.getPolicyNumber());
        //查询条件--保全受理号验证
        QueryCriteriaUtils.queryValidationByNumber(preservationVO.getPreservationAcceptanceNumber());
        //查询条件--姓名验证
        QueryCriteriaUtils.queryValidationByName(preservationVO.getPolicyHolderName(),preservationVO.getInsurederName());
        //查询条件--投保人证件验证
        QueryCriteriaUtils.queryValidationByCertificate(preservationVO.getPolicyHolderCertificateType(),preservationVO.getPolicyHolderCertificateNumber());
        //查询条件--被保人证件验证
        QueryCriteriaUtils.queryValidationByCertificate(preservationVO.getInsurederCertificateType(),preservationVO.getInsurederCertificateNumber());
        preservationVO.setUserJobNumber(UserDetailUtil.getUserDetail().getUserJobNumber());
        //调用外部接口获取保全进度列表信息
        SendHttpRequestUtils<PreservationVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(preservationVO,
                    cooperationCompanyUtils.getCompanyUrl(preservationVO.getInsuranceCompanyName(), CompanyParameterTypeEnum.QUERY_POLICY_PRESERVATION.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,PreservationProgressListBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(SystemParamsEnum.QUERY_POLICY_PRESERVATION.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(preservationVO, url).toJSONString(),PreservationProgressListBO.class);
        }
        return null;
    }
    /**
     * 根据保单号获取保全进度详情
     *
     * @param preservationProgressInfoVO 个人保单保全进度详情查询条件
     *
     * @return 个人保单保全进度详情查询条件
     */
    @Override
    public PreservationProgressInfoBO getPreservationProgressInfo(PreservationProgressInfoVO preservationProgressInfoVO){
        if(StringUtils.isEmpty(preservationProgressInfoVO.getPreservationAcceptanceNumber())){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL.getResultCode(),BaseErrorEnum.REQUEST_DATA_NULL.getResultMsg());
        }
        //获取用户工号
        preservationProgressInfoVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取个单保全进度详情信息
        SendHttpRequestUtils<PreservationProgressInfoVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(preservationProgressInfoVO,
                    cooperationCompanyUtils.getCompanyUrl(preservationProgressInfoVO.getInsuranceCompanyName(), CompanyParameterTypeEnum.QUERY_POLICY_PRESERVATION_INFO.getCode()));
            Object data = response.get("data");
            if( response != null){
                return JSON.toJavaObject(JSONObject.parseObject(JSONUtil.toJsonStr(data)),PreservationProgressInfoBO.class);
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(CompanyParameterTypeEnum.QUERY_POLICY_PRESERVATION_INFO.getCode());
            return JSON.toJavaObject(sendHttpRequest.sendHttpRequestToJson(preservationProgressInfoVO, url),PreservationProgressInfoBO.class);
        }
        return null;
    }

    /**
     * 根据查询条件获取理赔进度列表
     *
     * @param claimsVO 个人保单理赔进度列表查询条件
     *
     * @return 个人保单理赔进度列表
     */
    @Override
    public List<ClaimsProgressListBO> getClaimsProgressList(ClaimsVO claimsVO){
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(claimsVO.getApplicationStartDate(),claimsVO.getApplicationDeadline());
        //查询条件--保单号验证
        QueryCriteriaUtils.queryValidationByNumber(claimsVO.getPolicyNumber());
        //查询条件--报案号验证
        QueryCriteriaUtils.queryValidationByNumber(claimsVO.getReportNumber());
        //查询条件--赔案号验证
        QueryCriteriaUtils.queryValidationByNumber(claimsVO.getClaimsNumber());
        //查询条件--姓名验证
        QueryCriteriaUtils.queryValidationByName(claimsVO.getPolicyHolderName(),claimsVO.getInsurederName());
        //查询条件--投保人证件验证
        QueryCriteriaUtils.queryValidationByCertificate(claimsVO.getPolicyHolderCertificateType(),claimsVO.getPolicyHolderCertificateNumber());
        //查询条件--被保人证件验证
        QueryCriteriaUtils.queryValidationByCertificate(claimsVO.getInsurederCertificateType(),claimsVO.getInsurederCertificateNumber());
        claimsVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取理赔进度信息
        SendHttpRequestUtils<ClaimsVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(claimsVO,
                    cooperationCompanyUtils.getCompanyUrl(claimsVO.getInsuranceCompanyName(), CompanyParameterTypeEnum.QUERY_POLICY_CLAIMS.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,ClaimsProgressListBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(CompanyParameterTypeEnum.QUERY_POLICY_CLAIMS.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(claimsVO, url).toJSONString(),ClaimsProgressListBO.class);
        }
        return null;
    }

    /**
     * 根据查询条件获取满期保单列表
     *
     * @param expirationPolicyVO 个人保单满期列表查询条件
     *
     * @return 个人保单满期列表
     */
    @Override
    public List<ExpirationPolicyBO> getExpirationPolicyList(ExpirationPolicyVO expirationPolicyVO){
        //查询条件--保单号验证
        QueryCriteriaUtils.queryValidationByNumber(expirationPolicyVO.getPolicyNumber());
        //查询条件--姓名验证
        QueryCriteriaUtils.queryValidationByName(expirationPolicyVO.getPolicyHolderName(),expirationPolicyVO.getInsurederName());
        //查询条件--投保人证件验证
        QueryCriteriaUtils.queryValidationByCertificate(expirationPolicyVO.getPolicyHolderCertificateType(),expirationPolicyVO.getPolicyHolderCertificateNumber());
        //查询条件--被保人证件验证
        QueryCriteriaUtils.queryValidationByCertificate(expirationPolicyVO.getInsurederCertificateType(),expirationPolicyVO.getInsurederCertificateNumber());
        expirationPolicyVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取满期保单数据
        SendHttpRequestUtils<ExpirationPolicyVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(expirationPolicyVO,
                    cooperationCompanyUtils.getCompanyUrl(expirationPolicyVO.getInsuranceCompanyName(), CompanyParameterTypeEnum.QUERY_POLICY_EXPIRATION.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,ExpirationPolicyBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(CompanyParameterTypeEnum.QUERY_POLICY_EXPIRATION.getCode());
            return  JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(expirationPolicyVO, url).toJSONString(),ExpirationPolicyBO.class);
        }
        return null;
    }

    /**
     * 根据查询条件获取续期保单列表
     *
     * @param renewalPolicyVO 个人保单续期列表查询条件
     *
     * @return 个人保单续期列表
     */
    @Override
    public List<RenewalPolicyListBO> getRenewalPolicyList(RenewalPolicyVO renewalPolicyVO){
        //查询条件--保单号验证
        QueryCriteriaUtils.queryValidationByNumber(renewalPolicyVO.getPolicyNumber());
        //查询条件--姓名验证
        QueryCriteriaUtils.queryValidationByName(renewalPolicyVO.getPolicyHolderName(),renewalPolicyVO.getInsurederName());
        //查询条件--投保人证件验证
        QueryCriteriaUtils.queryValidationByCertificate(renewalPolicyVO.getPolicyHolderCertificateType(),renewalPolicyVO.getPolicyHolderCertificateNumber());
        //查询条件--被保人证件验证
        QueryCriteriaUtils.queryValidationByCertificate(renewalPolicyVO.getInsurederCertificateType(),renewalPolicyVO.getInsurederCertificateNumber());
        renewalPolicyVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口查询续期保单列表
        SendHttpRequestUtils<RenewalPolicyVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(renewalPolicyVO,cooperationCompanyUtils.getCompanyUrl(renewalPolicyVO.getInsuranceCompanyName(),
                    CompanyParameterTypeEnum.QUERY_POLICY_RENEWAL.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,RenewalPolicyListBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(CompanyParameterTypeEnum.QUERY_POLICY_RENEWAL.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(renewalPolicyVO, url).toJSONString(),RenewalPolicyListBO.class);
        }
        return null;
    }
}
